package com.rambo.xpd.base.demo;

import com.rambo.xpd.base.handler.SAXHandler;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 * Create by Rambo on 2017/5/10
 * jdk rt.jar org 包 中
 * sax.jar 独立
 **/
public class SAXDemo {

    public static void main(String[] args) throws Exception {
        SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); //获取SAX分析器的工厂实例，专门负责创建SAXParser分析器
        SAXParser saxParser = saxParserFactory.newSAXParser();
        InputStream inputStream = new FileInputStream(new File(Thread.currentThread().getContextClassLoader().getResource("demo.xml").getPath()));

        SAXHandler xmlSAXHandler = new SAXHandler();
        saxParser.parse(inputStream, xmlSAXHandler);
        System.out.println(xmlSAXHandler.getStudentGridlbList().toString());
    }
}